package main

import (
	"encoding/json"
	"fmt"
	"strings"
)

type PaytmResHead struct {
	ResponseTimestamp string `json:"responseTimestamp"` //时间
	Version           string `json:"version"`
	ClientId          string `json:"clientId"`
	Signature         string `json:"signature"` //签名
}
type PaytmResBodyInfo struct {
	ResultStatus string `json:"resultStatus"`
	ResultCode   string `json:"resultCode"`
	ResultMsg    string `json:"resultMsg"`
}
type InitPaytmResBody struct {
	ResultInfo       PaytmResBodyInfo `json:"resultInfo"`
	TxnToken         string           `json:"txnToken"`
	IsPromoCodeValid bool             `json:"isPromoCodeValid"`
	Authenticated    bool             `json:"authenticated"`
}

type InitPaytmRes struct {
	Head PaytmResHead     `json:"head"`
	Body InitPaytmResBody `json:"body"`
}

type QueryPaytmStatusResBody struct {
	ResultInfo  PaytmResBodyInfo `json:"resultInfo"`
	TxnId       string           `json:"txnId"`
	BankTxnId   string           `json:"bankTxnId"`
	OrderId     string           `json:"orderId"`
	TxnAmount   string           `json:"txnAmount"`
	TxnType     string           `json:"txnType"`
	GatewayName string           `json:"gatewayName"`
	BankName    string           `json:"bankName"`
	PaymentMode string           `json:"paymentMode"`
	RefundAmt   string           `json:"refundAmt"`
	TxnDate     string           `json:"txnDate"`
	Mid         string           `json:"mid"`
}
type QueryPaytmStatusRes struct {
	Head PaytmResHead            `json:"head"`
	Body QueryPaytmStatusResBody `json:"body"`
}

type PostHead struct {
	Signature string `json:"signature"`
	Version   string `json:"version"`
}

type PostTxnAmount struct {
	Value    string `json:"value"`
	Currency string `json:"currency"`
}
type PostuserInfo struct {
	CustId string `json:"custId"`
}
type PostBody struct {
	RequestType string        `json:"requestType"`
	Mid         string        `json:"mid"`
	WebsiteName string        `json:"websiteName"`
	OrderId     string        `json:"orderId"`
	TxnAmount   PostTxnAmount `json:"txnAmount"`
	UserInfo    PostuserInfo  `json:"userInfo"`
	CallbackUrl string        `json:"callbackUrl"`
}
type PostData struct {
	Body string   `json:"body"`
	Head PostHead `json:"head"`
}




//参数与defer的关系
func DeferFunc1(i int) (t int) {
	t = i
	defer func() {
		t += 3
	}()
	return t
}

func DeferFunc2(i int) int {
	t := i
	defer func() {
		t += 3
	}()
	return t
}

func DeferFunc3(i int) (t int) {
	defer func() {
		t += i
	}()
	return 2
}

//const 与iota作用
const (
	x = iota
	y
	z = "zz"
	k
	p = iota
)

type PaytmDepositCallBackRes struct {
	CURRENCY     string `json:"CURRENCY"`
	GATEWAYNAME  string `json:"GATEWAYNAME"`
	RESPMSG      string `json:"RESPMSG"`
	BANKNAME     string `json:"BANKNAME"`
	PAYMENTMODE  string `json:"PAYMENTMODE"`
	MID          string `json:"MID"`
	RESPCODE     string `json:"RESPCODE"`
	TXNID        string `json:"TXNID"`
	TXNAMOUNT    string `json:"TXNAMOUNT"`
	ORDERID      string `json:"ORDERID"`
	STATUS       string `json:"STATUS"`
	BANKTXNID    string `json:"CURRENCY"`
	TXNDATE      string `json:"TXNDATE`
	CHECKSUMHASH string `json:"CHECKSUMHASH"`
}

func test1(){
	//str := "79 82 68 69 82 73 68 61 77 65 76 95 68 95 49 95 65 48 56 68 66 52 57 70 54 51 50 50 48 65 69 54 65 70 68 54 57 65 54 65 54 56 66 69 56 49 52 55 38 77 73 68 61 77 111 98 105 108 101 53 57 56 57 53 49 53 53 50 50 57 55 50 49 38 84 88 78 73 68 61 50 48 50 48 48 56 50 53 49 49 49 50 49 50 56 48 48 49 49 48 49 54 56 53 50 52 55 52 50 51 49 52 56 52 57 38 84 88 78 65 77 79 85 78 84 61 50 48 46 48 48 38 67 85 82 82 69 78 67 89 61 73 78 82 38 83 84 65 84 85 83 61 84 88 78 95 70 65 73 76 85 82 69 38 82 69 83 80 67 79 68 69 61 49 52 49 38 82 69 83 80 77 83 71 61 85 115 101 114 43 104 97 115 43 110 111 116 43 99 111 109 112 108 101 116 101 100 43 116 114 97 110 115 97 99 116 105 111 110 46 38 66 65 78 75 84 88 78 73 68 61 38 67 72 69 67 75 83 85 77 72 65 83 72 61 67 106 115 51 66 98 116 77 75 120 102 109 90 119 74 66 65 51 49 51 54 56 122 71 54 57 99 114 53 71 105 50 122 122 99 79 66 90 77 116 98 97 78 118 87 119 87 118 56 104 48 98 52 110 66 74 122 89 65 114 56 119 72 122 109 90 105 90 83 68 112 112 83 57 111 70 107 109 117 103 119 79 86 86 107 73 112 83 76 121 107 54 76 112 114 110 74 85 109 52 70 105 122 69 101 103 89 37 51 68"

	//strList := strings.Split(str, " ")
	//fmt.Println(strList)
	//strData := "ORDERID=MAL_D_1_5D7DA49E590594A82F4DAEECC0346BCA&MID=IndiaL76626227890388&TXNID=20200826111212800110168903342477437&TXNAMOUNT=10.00&CURRENCY=INR&STATUS=TXN_FAILURE&RESPCODE=141&RESPMSG=User has not completed transaction.&BANKTXNID=&CHECKSUMHASH=SfGGDOug8DrYaCRI+oO5GDCOB3ACUo3mUbr7yoH4kA8Y3l28JY9zEf0zf59Qe3ri/cjHI3LxklVYIeDgpvB5PsM0wWOeOSCSi2R2DyfBkug="
	//strData, _ = url.QueryUnescape(strData)
	strData := "ORDERID=MAL_D_1_5D7DA49E590594A82F4DAEECC0346BCA&MID=IndiaL76626227890388&TXNID=20200826111212800110168903342477437&TXNAMOUNT=10.00&CURRENCY=INR&STATUS=TXN_FAILURE&RESPCODE=141&RESPMSG=User+has+not+completed+transaction.&BANKTXNID=&CHECKSUMHASH=SfGGDOug8DrYaCRI%2BoO5GDCOB3ACUo3mUbr7yoH4kA8Y3l28JY9zEf0zf59Qe3ri%2FcjHI3LxklVYIeDgpvB5PsM0wWOeOSCSi2R2DyfBkug%3D"

	//for _, v := range strList{
	//	i ,_ := strconv.Atoi(v)
	//	a := fmt.Sprintf("%c",i)
	//	//fmt.Printf("%c", i)
	//	//fmt.Println(a)
	//	strData = strData + a
	//}
	fmt.Println(strData)
	arr := strings.Split(strData, "&")
	jsonStr := "{"
	for _, v := range arr {
		arr2 := strings.Split(v, "=")
		for _, d := range arr2 {
			jsonStr = jsonStr + "\"" + d + "\"" + ":"
		}
		jsonStr = strings.TrimRight(jsonStr, ":")
		jsonStr = jsonStr + ","
	}
	jsonStr = strings.TrimRight(jsonStr, ",")
	//jsonStr = strings.ReplaceAll(jsonStr, "=", ":")
	jsonStr = jsonStr + "}"
	fmt.Println(jsonStr)
	res := &PaytmDepositCallBackRes{}
	//jsonStr = "{\"ORDERID\":\"MAL_D_1_A08DB49F63220AE6AFD69A6A68BE8147\",\"MID\":\"Mobile59895155229721\",\"TXNID\":\"20200825111212800110168524742314849\",\"TXNAMOUNT\":\"20.00\",\"CURRENCY\":\"INR\",\"STATUS\":\"TXN_FAILURE\",\"RESPCODE\":\"141\",\"RESPMSG\":\"User+has+not+completed+transaction.\",\"BANKTXNID\":\n\"\",\"CHECKSUMHASH\":\"Cjs3BbtMKxfmZwJBA31368zG69cr5Gi2zzcOBZMtbaNvWwWv8h0b4nBJzYAr8wHzmZiZSDppS9oFkmugwOVVkIpSLyk6LprnJUm4FizEegY%3D\"}"
	err := json.Unmarshal([]byte(jsonStr), res)
	if err != nil {
		fmt.Printf("PaytmV3DepositCallback ERROR Unmarshal err:%+v  ", err)
	}
	fmt.Printf("res:%+v", res)

	checkData := map[string]interface{}{}
	jsonData, err := json.Marshal(res)

	err = json.Unmarshal([]byte(jsonStr), &checkData)
	fmt.Println(jsonData,err)
	delete(checkData, "CHECKSUMHASH")
	fmt.Printf("\ncheckData:%+v", checkData)


	checkData2 := map[string]string{}
	aa := ""
	aa = aa + checkData2["333"]
	fmt.Println("____________checkData_____", checkData2["333"], aa)
}


func main()  {
	str := "{\"head\":{\"responseTimestamp\":\"1598337048747\",\"version\":\"v1\",\"signature\":\"F3xAqpp9iGVAFIDcdBFnq61zzIE5qXZs7z8oceQ61P6ghCmZ/3JKnR6BnQ41UmOV4G+UF15oBfEBqML3DGvP+srE+AQq63HnJbIUAfVnu3w=\"},\n\"body\":{\"resultInfo\":{\"resultStatus\":\"TXN_FAILURE\",\"resultCode\":\"334\",\"resultMsg\":\"Invalid Order Id.\"},\"orderId\":\"MAL_D_1_44D3FF6D92F5DC36B1932CE8E12E0EF3\",\"mid\":\"Mobile75806854211489\"}} \n"
	data := &QueryPaytmStatusRes{}
	err := json.Unmarshal([]byte(str), data)
	if err != nil {
		fmt.Printf("err:%v \n", err)
	}
	fmt.Printf("data:%+v \n", data)

	str2 := `"ddd"`
	fmt.Println(str2)

	fmt.Println(DeferFunc1(1))
	fmt.Println(DeferFunc2(1))
	fmt.Println(DeferFunc3(1))

	fmt.Println(x,y,z,k, p)

	test1()


	answer := "<html>\n<body>\n<input id=\"response\" value=\"\" style=\"display: none;\">\n</body>\n<script type=\"text/javascript\">\nvar data = \"%s\";\ndocument.getElementById(\"response\").value = data;\n</script>\n</html>"
	answer = fmt.Sprintf(answer, "3333")
	fmt.Println(answer)

}